﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Yunwei.DAL;
using Yunwei.Domain.Models;
using Yunwei.IBizLogic;

namespace Yunwei.BizLogic
{
    public class OrderFoodService : BaseService<OrderFoodRel>, IOrderFoodService
    {
        public OrderFoodService() : base(RepositoryFactory.OrderFoodRepository) { }
        public IQueryable<OrderFoodRel> FindList(int number, int order_Id, int orderCode)
        {
            return FindPageList(out number, 1, number, order_Id, orderCode);
        }

        public IQueryable<OrderFoodRel> FindPageList(out int totalRecord, int pageIndex, int pageSize, int order_Id, int orderCode)
        {
            IQueryable<OrderFoodRel> _commonModels = CurrentRepository.Entities;
            if (order_Id > 0) _commonModels = _commonModels.Where(o => o.Order_Id == order_Id);

            _commonModels = Order(_commonModels, orderCode);
            totalRecord = _commonModels.Count();
            return PageList(_commonModels, pageIndex, pageSize).AsQueryable();
        }

        public IQueryable<OrderFoodRel> Order(IQueryable<OrderFoodRel> entitys, int orderCode)
        {
            switch (orderCode)
            {
                //默认排序
                default:
                    entitys = entitys.OrderByDescending(cm => cm.Food_Id);
                    break;
            }
            return entitys;
        }
    }
}
